package com.yaoli.ajob;

/**
 * Created by will on 2017/4/25.
 */
public class _563_BinaryTreeTilt {
    //得到 左右 树的和，相加的得带该结点的值，
    //相减得到 绝对值，并加到 total 上面

    int total = 0;

    public int findTilt(TreeNode root) {
        calc(root);

        return total;
    }

    public int calc(TreeNode node){
        if(node == null){
            return 0;
        }else{
            int left = calc(node.left);
            int right = calc(node.right);
            total = total + Math.abs(left - right);
            return left+right+node.val;
        }

    }
}
